//
//  VisitorView.swift
//  微博(swfit)
//
//  Created by YLW on 15/9/21.
//  Copyright © 2015年 YLW. All rights reserved.
//

import UIKit
import SnapKit

class VisitorView: UIView {
    
    
    func setInfo(imageName : String? , title : String)
    {
        messageLabel.text = title
        if imageName != nil
        {
            
            iconView.image = UIImage(named: imageName!)
            homeIconView.hidden = true
            sendSubviewToBack(maskIconView)
        }
        else
        {
            startAnim()
        }
        
        
        
    }
    
    private func startAnim()
    {
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        anim.toValue = 2 * M_PI
        anim.repeatCount = MAXFLOAT
        anim.duration = 20
        anim.removedOnCompletion = false
        iconView.layer.addAnimation(anim, forKey: nil)
        
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setUpUI()
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        
        setUpUI()
    }
    
    private func setUpUI()
    {
        addSubview(iconView)
        addSubview(homeIconView)
        addSubview(maskIconView)
        addSubview(messageLabel)
        addSubview(registerBtn)
        addSubview(loginBtn)
        
        for v in subviews
        {
            v.translatesAutoresizingMaskIntoConstraints = false
        }
        
        iconView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.snp_centerX)
            make.centerY.equalTo(self.snp_centerY).offset(-60)
        }
        
        homeIconView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconView.snp_centerX)
            make.centerY.equalTo(iconView.snp_centerY)
        }
        
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(homeIconView.snp_centerX)
            make.centerY.equalTo(homeIconView.snp_centerY).offset(100)
            make.width.equalTo(224)
            make.height.equalTo(35)
            
        }

        registerBtn.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(messageLabel.snp_left)
            
            make.top.equalTo(messageLabel.snp_bottom).offset(16)
            
            make.width.equalTo(100)
            make.height.equalTo(35)
        }
        
        loginBtn.snp_makeConstraints { (make) -> Void in
            make.right.equalTo(messageLabel.snp_right)
            make.top.equalTo(messageLabel.snp_bottom).offset(16)
            
            make.width.equalTo(100)
            make.height.equalTo(35)
        }
        
        maskIconView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left)
            make.right.equalTo(self.snp_right)
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(registerBtn.snp_bottom).offset(70)
        }
//               addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[mask]-0-|", options: [], metrics: nil, views: ["mask":maskIconView]))
//        addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[mask]-(btnHeight)-[reBtn]", options: [], metrics: ["btnHeight":-70], views: ["mask":maskIconView , "reBtn" : registerBtn]))
        
        backgroundColor = UIColor(white: 237/255.0, alpha: 1.0)
        

        

        
    }
    
    
    //MARK: - 懒加载
    private lazy var iconView :UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
    private lazy var homeIconView : UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
    private lazy var maskIconView : UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))
    private lazy var messageLabel : UILabel = UILabel(title: "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜", foutSize: 14, textColor: UIColor.darkGrayColor())
    lazy var registerBtn : UIButton = UIButton(imageName: "common_button_white_disable", title: "注册", fontSize: 14, titleColor: UIColor.orangeColor())
    lazy var loginBtn : UIButton = UIButton(imageName: "common_button_white_disable", title: "登录", fontSize: 14, titleColor: UIColor.darkGrayColor())
}
